#include "cpu_affinity.h"
#include "arm.h"

void init_affinity(cpu_affinity_t *aff) {
    aff->mask = 0;
    for (uint64_t i = 0; i < ARM_NUM_CPU; i++) {
        aff->mask |= 1ull << i;
    }
}

/**
 * only to mask out some CPUs.
 * it is not allowed to gain more CPUs by SYS_setaff.
 */
void set_affinity(cpu_affinity_t *aff, uint64_t mask) {
    aff->mask &= mask;
}

int test_affinity(cpu_affinity_t *aff) {
    int i = arm_cpuid();
    return (aff->mask >> i) & 1;
}